﻿#region Copyright information
// 
// Copyright © 2005-2013 Yongkee Cho. All rights reserved.
// 
// This code is a part of the Biological Object Library and governed under the terms of the
// GNU Lesser General  Public License (LGPL) version 2.1 which accompanies this distribution.
// For more information on the LGPL, please visit http://bol.codeplex.com/license.
// 
// - Filename: DbXref.cs
// - Author: Yongkee Cho
// - Email: yongkeecho@gmail.com
// - Date Created: 2013-01-25 3:25 PM
// - Last Modified: 2013-01-25 3:59 PM
// 
#endregion
using System;
using System.Runtime.Serialization;

namespace BOL.Models
{
    /// <summary>
    /// Represents a pointer to related information in another database.
    /// </summary>
    /// <see cref="http://www.insdc.org/db_xref.html"/>
    [DataContract]
    public struct DbXref : IIdentifiable, IEquatable<DbXref>
    {
        #region Public properties

        public string Database { get; private set; }

        public string Id { get; private set; }

        #endregion

        #region Constructor

        public DbXref(string database, string id)
            : this()
        {
            Database = database;
            Id = id;
        }

        #endregion

        #region Public method

        public static Uri GetUri(string database, string id)
        {
            throw new NotImplementedException();

            /*
            Database	Description	Example
            AceView/WormGenes	AceView Worm Genome	/db_xref="AceView/WormGenes:vha-6"
            AFTOL	Assembling the Fungal Tree of Life	/db_xref="AFTOL:959"
            AntWeb	Ant Database	/db_xref="AntWeb:CASENT0058943-D01"
            APHIDBASE	Aphid Genome Database	/db_xref="APHIDBASE:ACYPI007424"
            ApiDB	Apicomplexan Database Resources	/db_xref="ApiDB:cgd1_1090"
            ApiDB_CryptoDB	Cryptosporidium Genome Resources	/db_xref="ApiDB_CryptoDB:cgd7_20"
            ApiDB_PlasmoDB	Plasmodium Genome Resources	/db_xref="ApiDB_PlasmoDB: PF11_0344"
            ApiDB_ToxoDB	Toxoplasma Genome Resources	/db_xref="ApiDB_ToxoDB:49.m00014"
            ASAP	A Systematic Annotation Package for Community Analysis of Genomes	/db_xref="ASAP:ABE-0000006"
            ATCC	American Type Culture Collection database	/db_xref="ATCC:123456"
            ATCC(in host)		/db_xref="ATCC(in host):123456"
            ATCC(dna)		/db_xref="ATCC(dna):123456”
            Axeldb	A Xenopus laevis database	/db_xref="Axeldb:32B3.1"
            BDGP_EST	Berkeley Drosophila Genome Project EST database	/db_xref="BDGP_EST:123456"
            BDGP_INS	Berkeley Drosophila Genome Project database -- Insertion	/db_xref="BDGP_INS:123456"
            BEETLEBASE	Tribolium Genome Database -- Insertion	/db_xref="BEETLEBASE:TC030551"
            BGD	Bovine Genome Database	/db_xref="BGD:BT10004"
            BOLD	Barcode of Life database	/db_xref="Bold:EPAF263"
            CABRI	Common Access to Biological Resources and Information project	/db_xref="CABRI: ACC 424"
            CCAP	Culture Collection of algae and protozoa	/db_xref="CCAP: 1460/15"
            CDD	Conserved Domain Database	/db_xref="CDD:02194
            dbEST	EST database maintained at the NCBI.	/db_xref="dbEST:123456"
            dbProbe	NCBI Probe database Public registry of nucleic acid reagents	/db_xref="dbProbe:38"
            dbSNP	Variation database maintained at the NCBI.	/db_xref="dbSNP:4647"
            dbSTS	STS database maintained at the NCBI.	/db_xref="dbSTS:456789"
            dictyBase	Dictyostelium genome database	/db_xref="dictyBase:DDB0191090"
            EcoGene	Database of Escherichia coli Sequence and Function	/db_xref="EcoGene:EG11277"
            ENSEMBL	Database of automatically annotated genomic data	/db_xref="ENSEMBL:HUMAN-Clone-AC005612"
            EPD	Eukaryotic Promotor Database	/db_xref="EPD: EP00576"
            ERIC	Enteropathogen Resource Integration Center	/db_xref="ERIC:ABY-0246137"
            ESTLIB	EBI's EST library identifier	/db_xref="ESTLIB:1200"
            FANTOM_DB	Database of Functional Annotation of Mouse	/db_xref="FANTOM_DB:0610005A07"
            FBOL	International Fungal Working Group Fungal Barcoding	/db_xref="FBOL:2224"
            FLYBASE	Database of Genetic and molecular data of Drosophila.	/db_xref="FLYBASE:FBgn0000024"
            GABI	Network of Different Plant Genomic Research Projects	/db_xref="GABI:HA05J18"
            GDB	Human Genome Database accession numbers	/db_xref="GDB:G00-128-600"
            GeneDB	Curated gene database for Schizosaccharomyces pombe, Leishmania major and Trypanosoma brucei	/db_xref="GeneDB:SPCC285.16c"
            GeneID	Entrez Gene Database (replaces NCBI Locus Link)	/db_xref="GeneID:3054987"
            GI	GenInfo identifier, used as a unique sequence identifier for nucleotide and proteins	/db_xref="GI:1234567890"
            GO	Gene Ontology Database identifier	/db_xref="GO:123"
            GOA	Gene Ontology Annotation Database Identifier	/db_xref=" GOA :P01100"
            Greengenes	16S rRNA gene database	/db_xref="Greengenes:269185"
            GRIN	Germplasm Resources Information Network	/db_xref="GRIN:1005973"
            HGNC	Human Gene Nomenclature Database	/db_xref="HGNC:2041"
            H-InvDB	H-Invitational Database	/db_xref="H-InvDB:HIT000000001"
            HMP	Human Microbiome Project	/db_xref="HMP:0536"
            HOMD	Human Oral Microbiome Database	/db_xref="HOMD:tax_078"
            HSSP	Database of homology-derived secondary structure of proteins	/db_xref="HSSP:12GS"
            IMGT/GENE-DB	Immunogenetics database, immunoglobulin and T-cell receptor genes	/db_xref="IMGT/GENE-DB:IGKC"
            IMGT/LIGM	Immunogenetics database, immunoglobulins and T-cell receptors	/db_xref="IMGT/LIGM:U03895"
            IMGT/HLA	Immunogenetics database, human MHC	/db_xref="IMGT/HLA:HLA00031"
            Interpro	InterPro protein sequence database	/db_xref="InterPro:IPR002928"
            IRD	Influenza Research Database	/db_xref="IRD:CEIRS-CIP045-123456.2"
            ISFinder	Insertion sequence elements database	/db_xref="ISFinder:ISA1083-2"
            JCM	Japan Collection of Microorganisms	/db_xref="JCM:1339"
            JGIDB	JGI Genome Portal	/db_xref="JGIDB:Chluvu1_81011"
            JGI's Phytozome	Comparative genomics of plants	/db_xref="Phytozome:Glyma0021s00410"
            LocusID	NCBI LocusLink ID **Discontinued March 2005	/db_xref="LocusID:51199"
            MaizeGDB	Maize Genome Database unique identifiers	/db_xref="MaizeGDB:635633 "
            MGI	Mouse Genome Informatics	/db_xref="MGI:1894891"
            MIM	Mendelian Inheritance in Man numbers	/db_xref="MIM:123456"
            miRBase	The microRNA database	/db_xref="miRBase: MI0001857"
            MycoBank	Fungal Databases, Nomenclature and Species Banks	/db_xref="MycoBank:MB519473"
            NBRC	NITE Biological Resource Center	/db_xref="NBRC:3189"
            NextDB	Nematode Expression Pattern DataBase	/db_xref="NextDB:CELK01662"
            niaEST	NIA Mouse cDNA Project	/db_xref="niaEST:L0304H12-3"
            NMPDR	National Microbial Pathogen Data Resource	/db_xref="NMPDR:fig|306254.1.peg.183"
            NRESTdb	Natural Rubber EST database	/db_xref="NRESTdb:Y01A01"
            Osa1	Rice Genome Annotation Project	/db_xref="Osa1:LOC_Os01g12345"
            Pathema	Pathema Genome Resource	/db_xref="Pathema:BA_4405"
            PBmice	PiggyBac Mutagenesis Information Center	/db_xref="PBmice:38"
            PDB	Biological macromolecule three dimensional structure database	/db_xref="PDB:12GS"
            PFAM	Collection of protein families	/db_xref="PFAM:PF00003"
            PGN	Plant Genome Network	/db_xref="PGN:aam01-1ms3-a05"
            PIR	Protein Information Resource accession numbers	/db_xref="PIR:S12345"
            PomBase	Database of Structural and Functional Data for Schizosaccaromyces pombe	/db_xref="PomBase:SPBC1709.20"
            PSEUDO	EMBL pseudo protein identifier	/db_xref="PSEUDO:CAC44644.1"
            PseudoCap	Pseudomonas Genome Database	/db_xref="PseudoCap:PA0001"
            RAP-DB	Rice Annotation Project Database	/db_xref="RAP-DB:Os01g1234567"
            RATMAP	Rat Genome Database	/db_xref="RATMAP:5"
            RFAM	RNA families database of alignments and CMs	/db_xref="RFAM:RF00230"
            RGD		/db_xref="RGD:620528"
            RiceGenes	Rice database accession numbers	/db_xref="RiceGenes:AA231856"
            RZPD	Resource Centre Primary Database Clone Identifiers	/db_xref="RZPD:IMAGp998I142450Q6"
            SEED	The SEED Database	/db_xref="SEED:fig|83331.1.peg.1"
            SGD	Saccharomyces Genome Database	/db_xref="SGD:L0000470"
            SGN	SOL Genomics Network	/db_xref="SGN:E553090"
            SK-FST	Saskatoon Arabidopsis T-DNA mutant population - SK Collection	/db_xref="SK-FST: FST:SK32219"
            SoyBase	Glycine max Genome Database	/db_xref="SoyBase:Satt005"
            SubtiList	Bacillus subtilis genome sequencing project	/db_xref="SubtiList:BG10001"
            taxon	NCBI's taxonomic identifier	/db_xref="taxon:4932"
            The Arabidopsis IR	The Arabidopsis Information Resource	 /db_xref="TAIR:AT1F51370"
            TIGRFAM	TIGR protein families	/db_xref="TIGRFAM:TIGR00094"
            UNILIB	Unified Library Database, a library-level view of the EST and SAGE libraries present in dbEST, UniGene and SAGEmap	/db_xref="UNILIB:1002"
            UniProtKB/Swiss-Prot	section of the UniProt Knowledgebase, containing annotated records, which include curator-evaluated computational analysis, as well as, information extracted from the literature	/db_xref="UniProtKB/Swiss-Prot:P12345"
            UniProtKB/TrEMBL	section of the UniProt Knowledgebase, containing computationally analysed records waiting for full manual annotation	/db_xref=" UniProtKB/TrEMBL:Q00177"
            UNITE	Molecular database for the identification of fungi	/db_xref=" UNITE:UDB000157"
            VBASE2	Integrative database of germ-line V genes from the immunoglobulin loci of human and mouse	/db_xref="VBASE2:humIGKV165"
            VectorBase	Bioinformatics Resource Center for Invertebrate Vectors of Human Pathogens	/db_xref="VectorBase:ENSANGG00000007825"
            ViPR	Virus Pathogen Resource	  db_xref="ViPR:HRV-A34_p1058_sR263_2008"
            WorfDB	C. elegans ORFeome cloning project	/db_xref="WorfDB:pos-1"
            WormBase	Caenorhabditis elegans Genome Database	/db_xref="WormBase:R13H7"
            Xenbase	Xenopus laevis and tropicalis biology and genomics resource	/db_xref=Xenbase:XB-GENE-1019547
            ZFIN	Zebrafish Information Network	/db_xref="ZFIN:ZDB-GENE-011205-17"
            */
        }

        #endregion

        #region IQualifier implementation

        public string ToQualifierString()
        {
            return String.Format("/db_xref=\"{0}\"", ToString());
        }

        #endregion

        #region IEquatable<DbXref> implementation

        public bool Equals(DbXref other)
        {
            return Database.Equals(other.Database) & Id.Equals(other.Id);
        }

        #endregion

        #region Object overriden

        public override int GetHashCode()
        {
            return Database.GetHashCode() ^ Id.GetHashCode();
        }

        public override string ToString()
        {
            return String.Format("{0}:{1}", Database, Id);
        }

        #endregion
    }
}
